<?php
/**
 * Created by lzl
 * Date: 2021 2021/9/26
 * Time: 14:09
 */
namespace App\Http\Controllers\Admin;

use App\Forms\PluginForms;

class PluginController extends Controller
{

    /**
     * 插件中心
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return $this->view('plugin.index', [
            'model' => (new PluginForms())->getPluginList()
        ]);
    }


    /**
     * 安装插件
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function install()
    {
        $rules = [
            'code' => 'required'
        ];

        $this->validateInput($rules);

        return $this->success((new PluginForms())->install($this->validated));
    }


    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     * @throws \App\Exceptions\RequestException
     */
    public function edit()
    {
        $rules = [
            'id' => 'required',
            'pay_description' => 'nullable',
        ];

        $this->validateInput($rules);

        if($this->request->ajax()) {
            return $this->success((new PluginForms())->edit($this->validated['id'], $this->validated));
        }

        return $this->view('plugin.edit',[
            'model' => (new PluginForms())->getDetailById($this->validated['id'])
        ]);
    }
}